package com.ruoyi.cbs.violation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cbs.violation.domain.vo.AddViolationRecordReqVO;
import com.ruoyi.cbs.violation.domain.vo.UpdateViolationRecordReqVO;
import com.ruoyi.cbs.violation.domain.vo.ViolationRecordReqVO;
import com.ruoyi.cbs.violation.domain.vo.ViolationRecordRespVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cbs.violation.domain.ViolationRecord;
import com.ruoyi.cbs.violation.service.IViolationRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 承包商违章记录Controller
 * 
 * @author ruoyi
 * @date 2025-11-15
 */
@RestController
@RequestMapping("/workplace/violation")
public class ViolationRecordController extends BaseController
{
    @Autowired
    private IViolationRecordService violationRecordService;

    /**
     * 查询承包商违章记录列表
     */
    @PreAuthorize("@ss.hasPermi('workplace:violation:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViolationRecordReqVO violationRecordReqVO)
    {
        startPage();
        List<ViolationRecordRespVO> list = violationRecordService.selectViolationRecordList(violationRecordReqVO);
        return getDataTable(list);
    }

    /**
     * 导出承包商违章记录列表
     */
    @PreAuthorize("@ss.hasPermi('workplace:violation:export')")
    @Log(title = "承包商违章记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViolationRecordReqVO violationRecord)
    {
        List<ViolationRecordRespVO> list = violationRecordService.selectViolationRecordList(violationRecord);
        ExcelUtil<ViolationRecordRespVO> util = new ExcelUtil<ViolationRecordRespVO>(ViolationRecordRespVO.class);
        util.exportExcel(response, list, "承包商违章记录数据");
    }

    /**
     * 获取承包商违章记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('workplace:violation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(violationRecordService.selectViolationRecordById(id));
    }

    /**
     * 新增承包商违章记录
     */
    @PreAuthorize("@ss.hasPermi('workplace:violation:add')")
    @Log(title = "承包商违章记录", businessType = BusinessType.INSERT)
    @PostMapping("/addRecord")
    public AjaxResult add(@RequestBody AddViolationRecordReqVO violationRecord)
    {
        return toAjax(violationRecordService.insertViolationRecord(violationRecord));
    }

    /**
     * 修改承包商违章记录
     */
    @PreAuthorize("@ss.hasPermi('workplace:violation:edit')")
    @Log(title = "承包商违章记录", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRecord")
    public AjaxResult edit(@RequestBody UpdateViolationRecordReqVO updateViolationRecordReqVO)
    {
        return toAjax(violationRecordService.updateViolationRecord(updateViolationRecordReqVO));
    }

    /**
     * 删除承包商违章记录
     */
    @PreAuthorize("@ss.hasPermi('workplace:violation:remove')")
    @Log(title = "承包商违章记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(violationRecordService.deleteViolationRecordByIds(ids));
    }
}
